import 'dart:convert';

import 'package:flutter/material.dart';

class Friend {

  @required final String avatar;
  @required final String name;
  @required final String email;

  Friend(this.avatar, this.name, this.email);

  static List<Friend> resolveDataFromResponse(String response){
    var json = jsonDecode(response);
    var results = json['results'];
    print("========results:$results");
    var result = results
    .map((obj) => Friend.fromMap(obj))
    .toList()
    .cast<Friend>();

    return result;

  }

  static Friend fromMap(Map map){
    var name = map['name'];
    return Friend(map['picture']['large'],
        '${name['first']} ${name['last']}', map['email']);
  }
}